In [1]:
%pylab inline
import numpy as np #  convert list to array

import matplotlib.pyplot as plt

from ipywidgets import *  #interaktivitáshoz szükséges függvények
from mpl_toolkits.mplot3d import * #3D-s ábrák alcsomagja

#from scipy import special 
from scipy.special import jn,fresnel
Populating the interactive namespace from numpy and matplotlib

Egy rés (apertura) Fraunhofer-diffrakciója

In [2]:
def int_1res(x,k,d):
    amp = (sin(k*d*x/2))/(k*d*x/2)
    intenz = (abs(amp))**2
    return(amp,intenz)

def int_kor(x):
    tmp = 4*(jn(1,x)/x)**2  
    return(tmp)
In [3]:
# Az abra kimentesehez az alabbiakat a plt.show()  ele kell tenni!!! 

#savefig('fig_rainbow_p2_1ray.pdf');  # Abra kimentese
#savefig('fig_rainbow_p2_1ray.eps');  # Abra kimentese

# Abra es fontmeretek
xfig_meret= 9   #    12 nagy abrahoz
yfig_meret= 6    #   12 nagy abrahoz
xyticks_meret= 15  #  20 nagy abrahoz
xylabel_meret= 20  #  30 nagy abrahoz
legend_meret= 17   #  30 nagy abrahoz

1) Vékony rés

$I(\vartheta) = I_0 \, \frac{\sin^2\left(k\frac{d}{2}\sin\vartheta\right)}{{\left(k\frac{d}{2} \sin\vartheta\right)}^2}$

In [4]:
lam =1;
d = 2*lam;
xm= 3.25*lam/d

sinvec= linspace(-xm,xm,200)
intvec=int_1res(sinvec,2*pi/lam,d)[1]

i0vec= []
sinzero=[]
mrange=[-3,-2,-1,1,2,3]

[sinzero.append(m*lam/d) for m in mrange]
[i0vec.append(int_1res(sinzero[i],2*pi/lam,d)[1]) for i in range(len(sinzero))]

#figsize(8,8)   
figsize(xfig_meret,yfig_meret)


plot(sinvec,intvec);

text(0.4,0.82,r'minimum helye:',fontsize=12)
text(0.4,0.75,r'$d\, \sin \vartheta = m, \mathrm{ahol} $',fontsize=18)
text(0.4,0.67,r'$m = \pm 1,\pm 2, \pm3, \dots $',fontsize=18)

labels = [r'$-3\,\frac{\lambda}{d}$',r'$-2\,\frac{\lambda}{d}$',r'$-\frac{\lambda}{d}$',
          r'$\frac{\lambda}{d}$',r'$2\,\frac{\lambda}{d}$',r'$3\,\frac{\lambda}{d}$']
xticks(sinzero,labels,fontsize=16)

title('Vékony rés')
xlabel(r'$\sin\vartheta$',fontsize=20)
ylabel(r'$\frac{I(\vartheta)}{I_0}$',fontsize=25, rotation=0, labelpad=30)

axis('tight')
xlim=(-xm,xm)


grid();
In [5]:
@interact(lam=(1),d=(0.5,10,0.5))
def play(d=1):

    xm= 3.25*lam/d

    sinvec= linspace(-xm,xm,200)
    intvec=int_1res(sinvec,2*pi/lam,d)[1]

    i0vec= []
    sinzero=[]
    mrange=[-3,-2,-1,1,2,3]

    [sinzero.append(m*lam/d) for m in mrange]
    [i0vec.append(int_1res(sinzero[i],2*pi/lam,d)[1]) for i in range(len(sinzero))]

    figsize(10,5)   
    #figsize(xfig_meret,yfig_meret)


    plot(sinvec,intvec);

    #text(0.4,0.82,r'minimum helye:',fontsize=12)
    #text(0.4,0.75,r'$d\, \sin \vartheta = m, \mathrm{ahol} $',fontsize=18)
    #text(0.4,0.67,r'$m = \pm 1,\pm 2, \pm3, \dots $',fontsize=18)

    labels = [r'$-3\,\frac{\lambda}{d}$',r'$-2\,\frac{\lambda}{d}$',r'$-\frac{\lambda}{d}$',
          r'$\frac{\lambda}{d}$',r'$2\,\frac{\lambda}{d}$',r'$3\,\frac{\lambda}{d}$']
    #xticks(sinzero,labels,fontsize=16)

    xlabel(r'$\sin\vartheta$',fontsize=20, rotation=0)
    ylabel(r'$\frac{I(\vartheta)}{I_0}$',fontsize=25, rotation=0, labelpad=30)

    axis('tight')
    xlim=(-xm,xm)


    grid();

2) Téglalap alakú rés

In [6]:
apb= 1  # a/b, a teglalap oldalainak aranya
xyr=12

figsize(15,4) 

subplot(1,3,1,aspect=1)
kx,ky = meshgrid(linspace(-xyr,xyr,100),linspace(-xyr,xyr,100)) #mintavételezési pontok legyártása
z2 = (sin(apb*kx)*sin(ky)/kx/ky)**2  #függvény kiértékelés
contourf(kx,ky,z2,levels=linspace(0.,0.02,50),cmap='gray');

title( r'$a/b = $' + str(apb), fontsize=18)
suptitle('Téglalap alakú rés', fontsize=16)

#axes().set_aspect('equal')
#colorbar();

subplot(1,3,2,aspect=1)
apb =2  # a/b, a teglalap oldalainak aranya
z2 = (sin(apb*kx)*sin(ky)/kx/ky)**2  #függvény kiértékelés
contourf(kx,ky,z2,levels=linspace(0.,0.02,50),cmap='gray');
title( r'$a/b = $' + str(apb), fontsize=18)

subplot(1,3,3,aspect=1)
apb =4  # a/b, a teglalap oldalainak aranya
z2 = (sin(apb*kx)*sin(ky)/kx/ky)**2  #függvény kiértékelés
     
contourf(kx,ky,z2,levels=linspace(0.,0.02,50),cmap='gray');

title( r'$a/b = $' + str(apb), fontsize=18);

subplots_adjust(left=0.2, wspace=0.8, top=0.8)

3) Kör alakú rés

In [7]:
lam= 550/10**9   # m
R= 0.5/1000  # m

kR = 2*pi/lam*R

print("első minimum, theta1 = ", 1.22*lam/2/R)
print("kR = ", around(kR,2))

thm = 4* 1.22*lam/2/R
thvec=linspace(-thm,thm,500)
xvec=kR*sin(thvec)

#figsize(8,8)   
figsize(xfig_meret,yfig_meret)

plot(thvec,int_kor(xvec))

title('Kör alakú rés')
xlabel(r'$\vartheta$',fontsize=20, rotation=0)
ylabel(r'$\frac{I(\vartheta)}{I_0}$',fontsize=25, rotation=0, labelpad=30)

axis('tight')
xlim=(-xm,xm)

grid();
első minimum, theta1 =  0.000671
kR =  5711.99
In [8]:
xym=0.1;

lam= 550/10**9
R= 0.5/1000
kR = 2*pi/lam*R

d= 1
xr= 4* 1.22*lam/2/R
xyr= xr *d

print("első minimum = theta_1 = ", 1.22*lam/2/R)
print("kR = ", around(kR,2))
print("range = ", xyr)

x2,y2 = meshgrid(linspace(-xyr,xyr,100),linspace(-xyr,xyr,100)) #mintavételezési pontok legyártása
z2 = int_kor(kR*sqrt(x2**2+y2**2)/d)  #függvény kiértékelés
     
figsize(8,8)   
#figsize(xfig_meret,yfig_meret)


#pcolor(x2,y2,z2,cmap='viridis');
res=contourf(x2,y2,z2,levels=linspace(0.,0.01,100),cmap='gray')
axes().set_aspect('equal')
title('Kör alakú rés',fontsize=16)
xlabel(r'$\sin\,\alpha_1$',fontsize=16)
ylabel(r'$\sin\,\alpha_2$',fontsize=16)

#colorbar();
colorbar(res, fraction=0.046, pad=0.04);
első minimum = theta_1 =  0.000671
kR =  5711.99
range =  0.002684
/home/cserti/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)
In [9]:
xym=0.1;

lam= 550/10**9
R= 0.5/1000
kR = 2*pi/lam*R

d= 1
xr= 4* 1.22*lam/2/R
xyr= xr *d

print("első minimum = theta_1 = ", 1.22*lam/2/R)
print("kR = ", around(kR,2))
print("range = ", xyr)

x2,y2 = meshgrid(linspace(-xyr,xyr,100),linspace(-xyr,xyr,100)) #mintavételezési pontok legyártása
z2 = int_kor(kR*sqrt(x2**2+y2**2)/d)  #függvény kiértékelés
 
fig = plt.figure(figsize(8,8))
ax = fig.add_subplot(1, 1, 1)

#figsize(8,8)   
#figsize(xfig_meret,yfig_meret)


#pcolor(x2,y2,z2,cmap='viridis');
res=ax.contourf(x2,y2,z2,levels=linspace(0.,0.01,100),cmap='gray')
ax.set_aspect('equal')
ax.set_title('Kör alakú rés',fontsize=16)
ax.set_xlabel(r'$\sin\,\alpha_1$',fontsize=16)
ax.set_ylabel(r'$\sin\,\alpha_2$',fontsize=16)

#fig.colorbar(res);
colorbar(res, fraction=0.046, pad=0.04);
első minimum = theta_1 =  0.000671
kR =  5711.99
range =  0.002684
In [10]:
fig = plt.figure(figsize(8,8))
ax = fig.add_subplot(1, 1, 1)

res=contourf(x2,y2,z2,levels=linspace(0.,0.01,30),cmap='viridis')
axes().set_aspect('equal')
ax.set_title('Kör alakú rés')

#fig.colorbar(res);
colorbar(res, fraction=0.046, pad=0.04);
/home/cserti/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)
In [11]:
xym=0.1;

lam= 550/10**9
R= 0.5/1000
kR = 2*pi/lam*R

d= 1
xr= 2* 1.22*lam/2/R
xyr= xr *d

Np=100
x2,y2 = meshgrid(linspace(-xyr,xyr,Np),linspace(-xyr,xyr,Np)) #mintavételezési pontok legyártása
z2 = int_kor(kR*sqrt(x2**2+y2**2)/d)  #függvény kiértékelés
 
#fig, ax = plt.subplots(1,1,1, figsize=(10,5))

#%matplotlib inline

fig = plt.figure(figsize=(10,8))
ax = fig.gca(projection='3d')

#ax = fig.add_subplot(111, projection='3d')


res = ax.plot_surface(x2, y2, z2, rstride=1, cstride=1, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)
ax.set_title('Kör alakú rés');
ax.axis('tight');

colorbar(res, fraction=0.046, pad=0.04);
In [12]:
#contourf(x2,y2,z2,levels=linspace(0.,0.01,30),cmap='viridis')

Np=100
xym=0.1;

lam= 550/10**9
R= 0.5/1000
kR = 2*pi/lam*R

d= 1
xr= 4* 1.22*lam/2/R
xyr= xr *d


x2,y2 = meshgrid(linspace(-xyr,xyr,Np),linspace(-xyr,xyr,Np)) #mintavételezési pontok legyártása
z2 = int_kor(kR*sqrt(x2**2+y2**2)/d)  #függvény kiértékelés

fig=figure(figsize(12,6))
ax = subplot(111, projection='3d')
res=ax.plot_surface(x2, y2, z2,rstride=1,cstride=1,cmap=cm.coolwarm,antialiased=True)
#axes().set_aspect('equal')
ax.set_title('Kör alakú rés');
ax.set_zlim(0.0, 0.05);

#colorbar(res, fraction=0.046, pad=0.04);
In [13]:
Np=100
xym=0.1;

lam= 550/10**9
R= 0.5/1000
kR = 2*pi/lam*R

d= 1
xr= 2* 1.22*lam/2/R
xyr= xr *d


x2,y2 = meshgrid(linspace(-xyr,xyr,Np),linspace(-xyr,xyr,Np)) #mintavételezési pontok legyártása
z2 = int_kor(kR*sqrt(x2**2+y2**2)/d)  #függvény kiértékelés
 
fig=figure(figsize(12,6))
ax = subplot(111)

cs=contour(x2,y2,z2,levels=linspace(0,0.01,5))
axes().set_aspect('equal')
ax.set_title('Kör alakú rés')

clabel(cs);
/home/cserti/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  warnings.warn(message, mplDeprecation, stacklevel=1)